// TypeScript file
class CircleCreatePanel extends CreatePanel {

    private btnConf = {
        seat: {//人数 2 3 4
            2: "btn_seat_2",
            3: "btn_seat_3",
            4: "btn_seat_4"
        },
        seal: {//封顶
            2: "btn_seal_2",
            3: "btn_seal_3",
            4: "btn_seal_4",
        },
        round: {//局数  
            4: "btn_round_1",
            8: "btn_round_2"
        },
        rules: {//规则映射 按钮
            [RuleType.zimojiadi]: "btn_rule_0",
            [RuleType.zimojiafan]: "btn_rule_1",
            [RuleType.dianganghua_pao]: "btn_rule_2",
            [RuleType.dianganghua_zimo]: "btn_rule_3",
            [RuleType.huansanzhang]: "btn_rule_4",
            [RuleType.yaojiujiangdui]: "btn_rule_5",
            [RuleType.menqingzhongzhang]: "btn_rule_6",
            [RuleType.tiandihu]: "btn_rule_7",
            [RuleType.xueliuchenghe]: "btn_type_1",
            [RuleType.xuezhandaodi]: "btn_type_2",
        }
    }

    protected createdChildren() {
        super.createChildren();

    }

    protected sendCreate() {
        let config = this.duijuConfig[this.getSeat()];
        if (config) {
            let m_rule: any = {};
            m_rule.id = Circle.args_2015.id;
            m_rule.uid = Circle.args_2015.uid;
            m_rule.owner_uid = Circle.args_2015.owner_uid;
            m_rule.rules = this.getRule();
            m_rule.round_type = config[this.getRound()].type;
            m_rule.ren = this.getSeat();
            m_rule.round = config[this.getRound()].count;
            game.askPanel.showMsg((r) => {
                m_rule.right_now = r ? 1 : 0;
                gameManager.socketManager.send(2020, m_rule);

            }, '确定立即生效新规则吗，如果确定，则会踢出当前未开始房间的玩家，如果取消，则玩法将在下一个新开的房间中生效。', null, null, false, true);
        }
    }

    public show() {
        game.isDaikai = true;
        super.show();
        this.skinState = "circle";
        this.initBtns();
    }
    public hide() {
        super.hide();
        GSDataProxy.i.sendCircleOpen();
    }

    public initBtns() {
        let nokai = Circle.circleNokai;
        let btn: string;
        let conf = this.btnConf;

        //模式
        let round: number = nokai.round;
        if (nokai.round_type == RoundType.quan) {
            round = round * 4;
        }
        btn = conf.round[round];
        this.setBtn(btn);
        //人数
        btn = conf.seat[nokai.renshu];
        this.setBtn(btn);
        //玩法
        let rules = nokai.rules;
        rules.forEach((rule) => {
            switch (typeof rule) {
                case "number":
                    btn = conf.rules[rule];
                    this.setBtn(btn);
                    break;
                case "object"://复合结构规则 如封顶[封顶,番数]
                    var _rule = rule[0];
                    switch (_rule) {
                        case RuleType.fengding:
                            btn = conf.seal[rule[1]];
                            this.setBtn(btn);
                            break;
                    }
                    break;
            }
        });
        //封顶
        this.update();
    }
    public setBtn(btn: string) {
        let box: eui.CheckBox = this[btn];
        if (box) {
            box.selected = true;
        }
    }

    /**子类重写 */
    public getCost() {
        return 1;
    }
    localSave() { }
    localRead() { }
}